package net.xo68.coordinator.core.gid;

import com.alipay.sofa.jraft.Closure;
import com.alipay.sofa.jraft.Status;
import com.alipay.sofa.jraft.closure.TaskClosure;
import lombok.extern.slf4j.Slf4j;

/**
 * leader服务端接收 请求的处理
 * @author wuxie
 * @version 2020-9-28
 */
@Slf4j
public class NewIdClosure implements TaskClosure {

    private GidServer gidServer;
    private NewIdRequest request;
    private NewIdResponse response;
    private Closure done;

    public NewIdClosure(GidServer gidServer, NewIdRequest request, NewIdResponse response, Closure done) {
        this.gidServer = gidServer;
        this.request = request;
        this.response = response;
        this.done = done;
    }

    @Override
    public void run(Status status) {
        if(this.done!=null){
            done.run(status);
        }
    }

    public NewIdRequest getRequest() {
        return request;
    }

    public NewIdResponse getResponse() {
        return response;
    }

    public Closure getDone() {
        return done;
    }

    @Override
    public void onCommitted() {
        log.info("#>> {} -请求已复制到多数节点",request);
    }
}
